package software.literature.view;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.layout.RowData;

public class BBGWindow extends Composite {

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public BBGWindow(Composite parent, int style) {
		super(parent, style);
		setLayout(new FormLayout());
		final Sash sash = new Sash(this, SWT.HORIZONTAL);
		final int limit = 20, percent = 60;
		final FormData sashData = new FormData();
		sashData.left = new FormAttachment(0, 0);
		sashData.right= new FormAttachment(100, 0);
		sashData.top = new FormAttachment(percent, 0);
		sash.setLayoutData(sashData);
		Image image = new Image(getDisplay(), "images/hsash_1.png");
		sash.setBackgroundImage(image);
		sash.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				Rectangle sashRect = sash.getBounds();
				Rectangle shellRect =BBGWindow.this.getClientArea();
				int bottom = shellRect.height - sashRect.height - limit;
				e.y = Math.max(Math.min(e.y, bottom), limit);
				if (e.y != sashRect.y) {
					sashData.top = new FormAttachment(0, e.y);
					BBGWindow.this.layout();
				}
			}
		});
		
		BBGListWindow group = BBGListWindow.getInstance(this, SWT.NONE);
		FormData fd_group = new FormData();
		fd_group.bottom =  new FormAttachment(sash, 0);
		fd_group.top =new FormAttachment(0,0);
		fd_group.right =  new FormAttachment(100, -3);
		fd_group.left = new FormAttachment(0, 3);
		group.setLayoutData(fd_group);
		BBGNoteWindow group_1 =BBGNoteWindow.getInstance(this, SWT.NONE);
		FormData fd_group_1 = new FormData();
		fd_group_1.bottom =  new FormAttachment(100, 0);
		fd_group_1.top =new FormAttachment(sash,0 );
		fd_group_1.right =  new FormAttachment(100, -1);
		fd_group_1.left = new FormAttachment(0, 3);
		group_1.setLayoutData(fd_group_1);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
